package cn.lovemmd.bms.mapper;

import cn.lovemmd.bms.pojo.Check;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;

@Mapper
public interface CheckMapper extends BaseMapper<Check> {
    @Insert("insert into bms_check(t_time,t_way,t_detail,t_remark,t_amount,icbc_balance,abc_balance,bc_balance,wechat_balance,overall_balance) values(#{tTime},#{tWay},#{tDetail},#{tRemark},#{tAmount},#{icbcBalance},#{abcBalance},#{bcBalance},#{wechatBalance},#{overallBalance})")
    Integer addCheck(String tTime,String tWay, String tDetail, String tRemark, BigDecimal tAmount, BigDecimal icbcBalance, BigDecimal abcBalance, BigDecimal bcBalance, BigDecimal wechatBalance, BigDecimal overallBalance);
    @Delete("delete from bms_check where t_id=#{tId}")
    Integer deleteCheck(int tId);
    @Delete("delete from bms_check where t_time between #{startTime} and #{endTime}")
    Integer deleteCheckByTimeInterval(String startTime, String endTime);
    @Update("update bms_check set t_way=#{tWay},t_detail=#{tDetail},t_remark=#{tRemark},t_amount=#{tAmount},icbc_balance=#{icbcBalance},abc_balance=#{abcBalance},bc_balance=#{bcBalance},wechat_balance=#{wechatBalance},overall_balance=#{overallBalance} where t_id=#{tId}")
    Integer updateCheck(int tId, String tWay, String tDetail, String tRemark, BigDecimal tAmount, BigDecimal icbcBalance, BigDecimal abcBalance, BigDecimal bcBalance, BigDecimal wechatBalance, BigDecimal overallBalance);
    @Select("select * from bms_check")
    IPage<Check> selectCheckPage(IPage<Check> page);
    @Select("select * from bms_check where t_time=#{time}")
    IPage<Check> selectCheckPageByTime(IPage<Check> page, String time);
    @Select("select * from bms_check where t_time between #{startTime} and #{endTime}")
    IPage<Check> selectCheckPageByTimeInterval(IPage<Check> page, String startTime, String endTime);
    @Select("select * from bms_check where t_way=#{tWay}")
    IPage<Check> selectCheckPageByWay(IPage<Check> page, String tWay);
    @Select("select * from bms_check where t_amount>#{amount}")
    IPage<Check> selectCheckPageByGreaterThanAmount(IPage<Check> page, BigDecimal amount);
    @Select("select * from bms_check where t_amount<#{amount}")
    IPage<Check> selectCheckPageByLessThanAmount(IPage<Check> page, BigDecimal amount);
    @Select("select sum(t_amount) from bms_check where t_amount<0")
    BigDecimal getTotalExpenditure();
    @Select("select sum(t_amount) from bms_check where t_amount>0")
    BigDecimal getGrossIncome();
    @Select("select * from bms_check where t_amount between #{minAmount} and #{maxAmount}")
    IPage<Check> selectCheckPageByAmountRange(IPage<Check> page, BigDecimal minAmount, BigDecimal maxAmount);

}
